package com.zhiwen.controller;

import com.zhiwen.util.JedisDistributLockUtil;

/**
 * @Auther: wuzhiwen
 * @Date: 2018/11/8 14:26
 * @Description:
 */
public class DistributedTest {

    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            final String finalI = Integer.toString(i);
            new Thread(new Runnable() {
                public void run() {
                    try {
                        Thread.currentThread().setName("test"+finalI);
                        String key = "TestRedisPower";
                        String value = finalI;
                        boolean testRedisPower = JedisDistributLockUtil.lock(key,value , 10 * 1000);
                        if(testRedisPower){
                            System.out.println(Thread.currentThread().getName()+"处理成功");
                            boolean b = JedisDistributLockUtil.releaseLock(key, value);
                        }else{
                            System.out.println(Thread.currentThread().getName()+"处理失败");
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }
}
